<template>
  <div class="login-wrapper" style="background-image: url(static/image/background-sci.jpeg)">
    <div class="form-box">
      <div class="form-title">
        <img src="static/image/pingtailogo.png" alt="icon">
        <p><b>用 户 登 录</b></p>
      </div>
      <el-form ref="loginForm" :model="loginForm" :rules="loginRules" label-width="0px" class="login-form">
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="请输入账号" prefix-icon="el-icon-user-solid" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="请输入密码" prefix-icon="el-icon-lock" @keyup.enter.native="handleLogin" />
        </el-form-item>
        <el-form-item>
          <el-checkbox v-model="loginForm.rememberMe"> <i class="el-icon-key"> </i>记住密码</el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button
            :loading="loading" size="medium" type="primary" round="true"
            style="width:100%;" @click.native.prevent="handleLogin">
            <span v-if="!loading">登 录</span>
            <span v-else>登 录 中...</span>
          </el-button>
        </el-form-item>
        <el-form-item class="form-title" style="font-family: Arial; color: #3b64ac" >
          <p><b>Designed By——Zhang Yuan-hang <br>  Support By——Chenchao</b></p>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  /*
  import { login } from '@/api/login'
  import { setToken } from '@/api/login'
  */
  //import Background from 'static/image/background.jpeg'
  export default {
    name: 'Login',
    data() {
      return {
        //Background,
        loginForm: {
          username: 'admin',
          password: 'admin123',
          rememberMe: true
        },
        loginRules: {
          username: [{ required: true, trigger: 'blur', message: '用户名不能为空'}],
          password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
        },
        loading: false,
        redirect: undefined
      }
    },
    watch: {
      $route: {
        handler: function(route) {
          this.redirect = route.query && route.query.redirect
        },
        immediate: true
      }
    },
    methods: {
      handleLogin() {
        this.$refs.loginForm.validate(valid => {
          const data = {
            username: this.loginForm.username,
            password: this.loginForm.password
          }
          if (valid) {
            this.loading = true
            /*
            login(data).then(res => {
              this.loading = false
              // setToken(res.token)

             */
              this.$router.push('/main')
            /*
            }).catch(() => {
              this.loading = false

             *})

             */
          }
        })
      }
    }
  }

</script>

<style lang="less">
  .login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    background-size: cover;
    .form-box {
      width: 390px;
      height: 540px;
      padding: 15px 30px 20px;
      background: #f2f2f2;
      border-radius: 4px;
      box-shadow: 0 15px 30px 0 rgba(0, 0, 1, 0.1);
      .form-title {
        margin: 0 auto 35px;
        text-align: center;
        font-family: 华文行楷;
        color: #3b64ac;
        font-size: 27px;
        letter-spacing: 0px;
      }
    }
  }
</style>
